package com.sky.controller.user;


import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.IDishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 菜品 前端控制器
 * </p>
 *
 * @author fcy
 * @since 2025-09-11
 */
@RestController("userDishController")
@RequestMapping("/user/dish")
@Api(tags = "C端菜品接口")
public class DishController {
    @Autowired
    private IDishService dishService;
    @Autowired
    private RedisTemplate redisTemplate;
    @ApiOperation("根据分类id查询菜品")
    @GetMapping("/list")
    public Result<List<DishVO>> list(Integer categoryId){
        String key="dish_"+categoryId;
        List<DishVO> list = (List<DishVO>) redisTemplate.opsForValue().get(key);
        if(list!=null&&list.size()>0){
            return Result.success(list);
        }
         list = dishService.getUserList(categoryId);
        redisTemplate.opsForValue().set(key,list);
        return Result.success(list);

    }
}
